//货柜与商品-报修申请
App.util.ns('Client.Apply.Repair');
App.pages.add((function(){
    var NS = Client.Apply.Repair;
    var page = new App.Page({
        name: 'client/apply/repair/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '报修申请'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/client/apply/repair',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: [
                    {name: '货柜', width: '120px', value: function(item){
                        return item.cabinet ? item.cabinet.name : '-- --';
                    }},
                    {name: '格子', width: '150px', value: function(item){
                        if(item.cell){
                            return '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列';
                        }
                        return '-- --';
                    }},
                    {name: '商品', width: '200px', value: function(item){
                        return item.cell && item.cell.goods ? item.cell.goods.name : '-- --';
                    }},
                    {name: '类型', width: '100px',value: function(item){
                        switch (item.type+'') {
                            case '1':
                                return '柜子问题';
                            case '2':
                                return '仪器问题';
                        }
                    }},
                    {name: '状态', width: '90px',value: function(item){
                        switch (item.status+'') {
                            case '0':
                                return '未处理';
                            case '1':
                                return '已处理';
                        }
                    }},
                    {name: '申请日期', width: '80px', value: function(item){
                        return App.util.formator.date(item.created_at);
                    }}
                ]
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '未处理'],
                    [1, '已处理']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:client.apply.repair.detail'},
                {type: 'inline', permission: 'op:client.apply.repair..finish', name: '处理完成', operation: {type: 'change', url: 'finish'}, conditions: [['status', '0']]},
                {parent: 'drop', permission: 'op:client.apply.repair..delete'},
                {type: 'multi', name: '状态', openable: true, permission: 'op:client.apply.repair..multiFinish', 
                    items: [
                        {
                            type: 'multi', permission: 'op:client.apply.repair..multiOnline', name: '处理完成', 
                            operation: {
                                type: 'change', url: 'multiFinish', confirm: true
                            }
                        }
                    ] 
                },
                {parent: 'multiDrop', permission: 'op:client.apply.repair..multiDelete'},
                {parent: 'oplog', permission: 'op:client.apply.repair..getOpLogs'}
            ],
            detail: {
                form: {
                    items: [
                        {type: 'hidden', name: 'id'},
                        {type: 'hidden', name: 'client_id'},
                        {type: 'hidden', name: 'cabinet_id'},
                        {type: 'hidden', name: 'cell_id'},
                        {type: 'static', name: 'cabinet_name', title: '货柜名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'cell_name', title: '格子位置', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'static', name: 'goods_name', title: '商品名称', rule: {
                            type: 'str',
                            range: [0, 255]
                        }},
                        {type: 'radio', name: 'type', title: '报修类型', required: true, 
                            items: [
                                [1, '柜子问题'],
                                [2, '仪器问题']
                            ],
                            defaults: '2',
                            rule: {
                                type: 'in',
                                in: ['1', '2']
                            }
                        },
                        {type: 'textarea', name: 'introduction', title: '补充说明', maxLength: 2000, rule: {
                            type: 'str',
                            range: [0, 2000]
                        }}
                    ],
                    onChange: function(self, item){
                        var cabinetName = item.cabinet ? item.cabinet.name : '-- --';
                        var cellName = item.cell ? '第 '+item.cell.row + ' 行，第' + item.cell.col + ' 列' : '-- --';
                        var goodsName = item.cell && item.cell.goods ? item.cell.goods.name : '-- --';
                        self.formItems['cabinet_name'].change(cabinetName);
                        self.formItems['cell_name'].change(cellName);
                        self.formItems['goods_name'].change(goodsName);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面显示
    page.showStack.add('dataTable', function(){
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());